package com.kaidi.dibankecloud.widget;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.kaidi.dibankecloud.R;

/**
 * Created by Administrator on 2017/1/9.
 */

public class MaintenancePopupWindow extends PopupWindow{
    private Context context;
    public MaintenancePopupWindow(Context context) {
        super(context);
        this.context = context;
        View rootView = LayoutInflater.from(context).inflate(R.layout.popup_maintenance, null);
        setContentView(rootView);
        setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        ColorDrawable dw = new ColorDrawable(0000000000);
        setBackgroundDrawable(dw);
        setOutsideTouchable(true);
        setFocusable(true);
        update();
    }
    public void showPopupWindow(View anchor){
        if(!isShowing()) {
            showAtLocation(anchor, Gravity.CENTER, 0, 0);
            Window window = ((Activity) context).getWindow();
            WindowManager.LayoutParams lp = window.getAttributes();
            lp.alpha = 0.5f;
            window.setAttributes(lp);
        }
    }
}
